import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.io.IOException;
import java.io.InputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;

public class DeCode {

    private static final String KEY = "AES";
    private static final String Copyright = "SSE tdgw-1.4.10";

    public static InputStream decode(byte[] d, InputStream paramInputStream) throws IOException {
        try {
            Cipher cipher = Cipher.getInstance(KEY);
            cipher.init(2, new SecretKeySpec(d, KEY));
            return new CipherInputStream(paramInputStream, cipher);
        } catch (Exception exception) {
            exception.printStackTrace();
            return null;
        }
    }

    public static byte[] getKey() throws NoSuchAlgorithmException {
        MessageDigest messageDigest = MessageDigest.getInstance("SHA-512");
        byte[] arrayOfByte = messageDigest.digest(Copyright.getBytes());
        KeyGenerator keyGenerator = KeyGenerator.getInstance(KEY.split("[/]")[0]);
        e e = new e(arrayOfByte);
        keyGenerator.init(128, (SecureRandom) e);
        SecretKey secretKey1 = keyGenerator.generateKey();
        byte[] d = secretKey1.getEncoded();
        System.out.println(d);
        return d;
//        keyGenerator.init(128, (SecureRandom) e);
//        SecretKey secretKey2 = keyGenerator.generateKey();
    }
}
